package com.ysc.IUDS;

import com.ysc.domain.Class;
import com.ysc.utils.mybatisUtils;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

public class Class_Information {

    //展示一个教师的所有班级的信息
    public static void ShowClassesByTid(int tid){
        SqlSession sqlSession = mybatisUtils.getSqlSession();
        String SqlID= "com.ysc.Dao.ClassDao.selectClassesbyTid";
        Class class1 = new Class();
        class1.setTid(tid);
        List<Class> classes = sqlSession.selectList(SqlID,class1);
        for (Class cla : classes){
            System.out.println(cla);
        }
        sqlSession.close();
    }

    //展示一个班级的信息
    public static void ShowClassesByCid(int cid){
        SqlSession sqlSession = mybatisUtils.getSqlSession();
        String SqlID= "com.ysc.Dao.ClassDao.selectClassesbyCid";
        Class class1 = new Class();
        class1.setCid(cid);
        List<Class> classes = sqlSession.selectList(SqlID,class1);
        for (Class cla : classes){
            System.out.println(cla);
        }
        sqlSession.close();
    }

    //展示一个班级的信息
    public static int GetTidByCid(int cid){
        SqlSession sqlSession = mybatisUtils.getSqlSession();
        String SqlID= "com.ysc.Dao.ClassDao.GetTidByCid";
        Class class1 = new Class();
        class1.setCid(cid);
        int tid = sqlSession.selectOne(SqlID,class1);
        sqlSession.close();
        return tid;
    }

    //获取班级当前人数
    public static int GetCNum(int cid){
        SqlSession sqlSession = mybatisUtils.getSqlSession();
        String SqlID= "com.ysc.Dao.ClassDao.getCnum";
        Class class1 = new Class();
        class1.setCid(cid);
        int Cnum = sqlSession.selectOne(SqlID,class1);
        sqlSession.close();
        return Cnum;
    }

    //给新报名的学生班级增添人数
    public static void UpdateCNum(int cid){
        SqlSession sqlSession = mybatisUtils.getSqlSession();
        String SqlID = "com.ysc.Dao.ClassDao.UpdateCNum";
        Class cla1 = new Class();
        cla1.setCid(cid);
        sqlSession.update(SqlID,cla1);
        sqlSession.commit();
        sqlSession.close();
    }
}
